package com.company.manage.system.utils;

import com.company.manage.system.entity.ShiroUser;
import com.company.manage.system.entity.User;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;

/**
 * Created by HuangYong on 2016/1/23.
 * desc: 用户对象工具类
 */
public class UserUtil {
    private static final String TAG = "UserUtil";

    /**
     * 获取当前用户对象shiro
     *
     * @return
     */
    public static ShiroUser getCurrentShiroUser() {
        ShiroUser shiroUser = (ShiroUser) SecurityUtils.getSubject().getPrincipal();
        return shiroUser;
    }

    /**
     * 获取当前用户sessio
     *
     * @return
     */
    public static Session getSession() {
        Session session = SecurityUtils.getSubject().getSession();
        return session;
    }

    /**
     * 获取当前用户httpsession
     *
     * @return
     */
    public static Session getHttpSession() {
        Session session = getSession();
        return session;
    }

    /**
     * 获取当前用户对象
     * @return
     */
    public static User getCurrentUser() {
        Session session = SecurityUtils.getSubject().getSession();
        if (null != session) {
            return (User) session.getAttribute("user");
        } else {
            return null;
        }
    }

} 